#define _CRT_SECURE_NO_WARNINGS 1

/*
* Copyright (C) 2021  BryantDai
* All rights reserved.

* This program is free software: you can use, modify and/or redistribute it under the terms of the GNU General Public
* License as published by the Free Software Foundation.
*/

/* Includes ---------------------------------------------------------------------------------------------------*/
#include <iostream>
#include "QuickShift.h"

/* Private typedef --------------------------------------------------------------------------------------------*/
/* Private define ---------------------------------------------------------------------------------------------*/
/* Private macro ----------------------------------------------------------------------------------------------*/
/* Private variables ------------------------------------------------------------------------------------------*/
/* Private function prototypes --------------------------------------------------------------------------------*/
/* Private functions ------------------------------------------------------------------------------------------*/

/**************************************************************************************************************
* @Name        : main
* @Brief       : main function body
* @Param       : argc : The number of parameters input in 'argv'
*                argv : Pointer to the address storing the parameters
* @Return      : None
* @Author      : Bryant
* @Create Date : Nov-10-2021
* @Mended by   :
* @Mend Date   :
* @Note        : (1) ratio      : Tradeoff between spatial consistency and color consistency. Small ratio gives more
*                                 importance to the spatial component.
*                    kernelSize : The standard deviation of the kernel used in the Parzen density estimate.
*                    maxDist    : The maximum distance between nodes in the quickshift tree. Used to cut links in the tree to form the segmentation.
***************************************************************************************************************/
int main(int argc, char** argv)
{
    if (argc != 5)
    {
        std::cout << "Input Paramters: csv_filename ratio kernelSize  maxDist" << std::endl; /* See Note(1)               */
        return -1;
    }

    /* Display the pamaters information                                                                         */
    std::cout << "Input File :" << argv[1] << std::endl;
    //std::cout << "ratio      = " << argv[2] << std::endl;
    //std::cout << "kernelSize = " << argv[3] << std::endl;
    //std::cout << "maxDist    = " << argv[4] << std::endl;

    /* Read image from disk and display                                                                         */
    cv::Mat g_srcImg = cv::imread(argv[1], cv::IMREAD_COLOR);
    cv::namedWindow("Origianl Image", cv::WINDOW_AUTOSIZE);
    cv::imshow("Origianl Image", g_srcImg);
    cv::waitKey(30);
    vector2L g_labelImg(g_srcImg.rows, std::vector<uint32_t>(g_srcImg.cols, 0));

    vector2D g_distMat(g_srcImg.rows, std::vector<double>(g_srcImg.cols, 0));
    QuickShift g_quickShiftClass(atof(argv[2]), atof(argv[3]), atof(argv[4]));
    cv::Mat g_dstImg = g_quickShiftClass.QuickShiftSegment(g_srcImg, g_labelImg, g_distMat);

    cv::namedWindow("Quickshift segment Image", cv::WINDOW_AUTOSIZE);
    cv::imshow("Quickshift segment Image", g_dstImg);
    cv::waitKey(0);
    return 0;
}




/********************************************* End of file ****************************************************/


